package com.ems.service;

import java.util.List;

import javax.persistence.EntityManager;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.ems.dto.DataBean;

@Service
public class TestServer {

	@Autowired
	private EntityManager entityManager;

	@Transactional(rollbackFor = Exception.class)
	public void add() {
		String sql = "insert into of_user(name,code) values('王工','wg')";
		entityManager.createNativeQuery(sql).executeUpdate();
	}

	@Transactional(rollbackFor = Exception.class)
	public void addDate(DataBean data) {
		String sql = data.toSql();
		entityManager.createNativeQuery(sql).executeUpdate();
	}

	public List query() {
		String sql = "SELECT statsyear,statsmonth,AVG(recordtime) FROM st_client_quarter_data WHERE clientcode='client1' AND (statsyear*10000 + statsmonth * 100 + statsday) > 20210101 AND (statsyear*10000 + statsmonth * 100 + statsday) < 20211231 GROUP BY statsyear,statsmonth";
		return entityManager.createNativeQuery(sql).getResultList();
	}
}
